//
//  LZSDaRenViewController.m
//  IOSProject
//
//  Created by lzs on 2018/4/20.
//  Copyright © 2018年 com.linzhisheng. All rights reserved.
//

#import "LZSDaRenViewController.h"
#import "LZSOneCell.h"

#import "LZSArticelDetailViewController.h"

@interface LZSDaRenViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation LZSDaRenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"人物专栏";
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor redColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorColor = [UIColor lightGrayColor];
    //
    self.tableView.estimatedRowHeight = 80;
    
    self.tableView.separatorColor = [UIColor colorWithHexString:@"#c8c8c8"];
    
    //默认【下拉刷新】
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
    //默认【上拉加载】
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    //
    self.tableView.tableFooterView = [UIView new];
    
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).mas_offset(0);
    }];
    
    //    [self headerSdcycleScrollView];
    
    //
    [self.tableView.mj_header beginRefreshing];
}

-(void)refresh{
//    sleep(2);
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

-(void)loadMore{
//    sleep(2);
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LZSOneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[LZSOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.titleLabel.text = @"文章名";
    cell.timeLabel.text = @"以前发表的文章的详细信息以前发表的文章的详情信息";
    cell.btn.hidden = YES;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerview = [[UIView alloc] init];
    headerview.layer.borderColor = [UIColor lightGrayColor].CGColor;
    headerview.layer.borderWidth = 0.5;
    headerview.backgroundColor  =[UIColor whiteColor];
    UIImageView *iconView = [[UIImageView alloc] init];
    iconView.backgroundColor = [UIColor blueColor];
    [headerview addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(headerview.mas_centerY).mas_offset(-15);
        make.left.equalTo(headerview.mas_left).mas_offset(15);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    
    UILabel *titleLabel = [self.view setuplabelwithfont:[UIFont systemFontOfSize:15] withText:@"民族" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentLeft];
    [headerview addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).mas_offset(15);
        make.right.equalTo(headerview.mas_right).mas_equalTo(-15);
        make.top.equalTo(iconView.mas_top);
    }];
    
    UILabel *desLabel = [self.view setuplabelwithfont:[UIFont systemFontOfSize:15] withText:@"民族" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentLeft];
    [headerview addSubview:desLabel];
    [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).mas_offset(15);
        make.right.equalTo(headerview.mas_right).mas_equalTo(-15);
        make.top.equalTo(titleLabel.mas_bottom).mas_offset(15);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [headerview addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(headerview);
        make.top.equalTo(iconView.mas_bottom).mas_offset(5);
        make.height.mas_equalTo(0.5);
    }];
    
    UILabel *articleLabel = [self.view setuplabelwithfont:[UIFont systemFontOfSize:15] withText:@"文章列表" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentLeft];
    [headerview addSubview:articleLabel];
    [articleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerview.mas_left).mas_offset(15);
        make.right.equalTo(headerview.mas_right).mas_equalTo(-15);
        make.top.equalTo(lineView.mas_bottom).mas_offset(8);
    }];
    return headerview;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 110;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LZSArticelDetailViewController *articlevc = [[LZSArticelDetailViewController alloc] init];
    [self.navigationController pushViewController:articlevc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
